<?php
class Tender_Join_BeginController extends Agitum_Controller_Action
{
	protected $_redirector = null;

	public function init() {
		$this->_redirector = $this->_helper->getHelper('Redirector');
	}

	public function indexAction()
	{
		$form = $this->_helper->formLoader('Begin');
		if ( $this->_request->isPost() ) {
			$params = $this->_request->getPost();
			if ( $form->isValid($params) ) {
				$begin = new Zend_Session_Namespace('tender/begin');
				foreach ( $params as $key => $value ) {
					$begin->$key = $value;
				}
				$this->_redirector->gotoUrl('/tender/wishes');
			}
		}
		$this->view->form = $form;
	}

	public function validateAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout()->disableLayout();

		$form = $this->_helper->formLoader('Begin');
		$form->isValid($this->_request->getPost());
		$json = $form->getMessages();

		$this->_response->setHeader('Content-Type', 'application/json');
		echo Zend_Json::encode($json);
	}

}